package lab02.test06;

import java.util.Scanner;

/**
 * Created by 林云志 on 2017/10/15.
 */
public class Triangle {
    public static void main(String[] args) {
        Scanner triangle = new Scanner(System.in);
        System.out.println("请输入三角形的三条边");
        boolean judge;
        double edge1 = triangle.nextInt();
        double edge2 = triangle.nextInt();
        double edge3 = triangle.nextInt();
        int s1 = 0;
        while (s1!= 2){
            judge = judge(edge1, edge2, edge3);
            if (judge) {
                System.out.println("周长为：" + perimeter(edge1, edge2, edge3));
                System.out.println("面积为：" + area(edge1, edge2, edge3));
            }
            System.out.println("如果需要修改边长则输入1,不需要请输入2结束程序");
            Scanner sc = new Scanner(System.in);
            s1 = sc.nextInt();
            if (s1 == 1) {
                System.out.println("输入1、2、3来选择修改的哪个边长");
                int s2 = sc.nextInt();
                System.out.println("请输入更改的边长");
                int s3 = sc.nextInt();
                switch (s2) {
                    case 1:
                        edge1 = s3;
                    case 2:
                        edge2 = s3;
                    case 3:
                        edge3 = s3;
                }


            }}}
    static double perimeter(double edge1,double edge2,double edge3){
        double perimeter = edge1 + edge2 +edge3;
        return  perimeter;
    }
    static double area (double edge1,double edge2,double edge3) {
        double p = (edge1 + edge2 + edge3 )/2;
        double area = Math.sqrt(p*(p-edge1)*(p-edge2)*(p-edge3));
        return area;
    }
    static boolean judge(double edge1,double edge2,double edge3){
        double max = edge1;
        boolean judge1;
        if (edge2 > edge1){
            max = edge2;
            if (edge3 > max){
                max = edge3;
            }
        }else if(edge3 > max){
            max = edge3;
        }
        double min = edge1;
        if (edge2 < edge1){
            min = edge2;
            if (edge3 < min){
                min = edge3;
            }
        }else if(edge3 < min){
            min = edge3;
        }
        double medium;
        if (edge1 >min && edge1 <max){
            medium = edge1;
        }else if (edge2 >min && edge2 <max){
            medium = edge2;
        }else medium = edge3;
        if (min+ medium > max){
            System.out.println("能构成三角形");
            judge1 = true;
        }else {
            System.out.println("不能构成三角形");
            judge1 = false;
        }
        /*System.out.println(min);
        System.out.println(max);
        System.out.println(medium);*/
        return judge1;
    }
}
